package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BieHouse;
import com.ruoyi.system.service.IBieHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房间Controller
 * 
 * @author zxl
 * @date 2021-05-03
 */
@RestController
@RequestMapping("/system/house")
public class BieHouseController extends BaseController
{
    @Autowired
    private IBieHouseService bieHouseService;

    /**
     * 查询房间列表
     */
    @PreAuthorize("@ss.hasPermi('system:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(BieHouse bieHouse)
    {
        startPage();
        List<BieHouse> list = bieHouseService.selectBieHouseList(bieHouse);
        return getDataTable(list);
    }

    /**
     * 导出房间列表
     */
    @PreAuthorize("@ss.hasPermi('system:house:export')")
    @Log(title = "房间", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BieHouse bieHouse)
    {
        List<BieHouse> list = bieHouseService.selectBieHouseList(bieHouse);
        ExcelUtil<BieHouse> util = new ExcelUtil<BieHouse>(BieHouse.class);
        return util.exportExcel(list, "房间数据");
    }

    /**
     * 获取房间详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:house:query')")
    @GetMapping(value = "/{houseId}")
    public AjaxResult getInfo(@PathVariable("houseId") String houseId)
    {
        return AjaxResult.success(bieHouseService.selectBieHouseById(houseId));
    }

    /**
     * 新增房间
     */
    @PreAuthorize("@ss.hasPermi('system:house:add')")
    @Log(title = "房间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BieHouse bieHouse)
    {
        return toAjax(bieHouseService.insertBieHouse(bieHouse));
    }

    /**
     * 修改房间
     */
    @PreAuthorize("@ss.hasPermi('system:house:edit')")
    @Log(title = "房间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BieHouse bieHouse)
    {
        return toAjax(bieHouseService.updateBieHouse(bieHouse));
    }

    /**
     * 删除房间
     */
    @PreAuthorize("@ss.hasPermi('system:house:remove')")
    @Log(title = "房间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseIds}")
    public AjaxResult remove(@PathVariable String[] houseIds)
    {
        return toAjax(bieHouseService.deleteBieHouseByIds(houseIds));
    }
}
